
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Django入门与实践-第14章：用户注册 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Authentication1.html" />
    
    
    <link rel="prev" href="AdvancedConcept3.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="GettingStarted.html">
            
                <a href="GettingStarted.html">
            
                    
                    Django入门与实践-第1章：环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="GettingStarted-2.html">
            
                <a href="GettingStarted-2.html">
            
                    
                    Django入门与实践-第2章：创建项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="gettingstarted-3.html">
            
                <a href="gettingstarted-3.html">
            
                    
                    Django入门与实践-第3章：Hello World
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Fundamentals-1.html">
            
                <a href="Fundamentals-1.html">
            
                    
                    Django入门与实践-第4章：系统设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Fundamentals-2.html">
            
                <a href="Fundamentals-2.html">
            
                    
                    Django入门与实践-第5章：模型设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Fundamentals-3-0.html">
            
                <a href="Fundamentals-3-0.html">
            
                    
                    Django入门与实践-第6章：第一个视图函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Fundamentals-3-1.html">
            
                <a href="Fundamentals-3-1.html">
            
                    
                    Django入门与实践-第7章：模板引擎设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Fundamentals-3-1-1.html">
            
                <a href="Fundamentals-3-1-1.html">
            
                    
                    Django入门与实践-第8章：第一个单元测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="Fundamentals-3-2.html">
            
                <a href="Fundamentals-3-2.html">
            
                    
                    Django入门与实践-第9章：静态文件设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="Fundamentals-4.html">
            
                <a href="Fundamentals-4.html">
            
                    
                    Django入门与实践-第10章：Django Admin 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="AdvancedConcepts.html">
            
                <a href="AdvancedConcepts.html">
            
                    
                    Django入门与实践-第11章：URL 分发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="AdvancedConcept2.html">
            
                <a href="AdvancedConcept2.html">
            
                    
                    Django入门与实践-第12章：复用模板
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="AdvancedConcept3.html">
            
                <a href="AdvancedConcept3.html">
            
                    
                    Django入门与实践-第13章：表单处理
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.15" data-path="Authentication0.html">
            
                <a href="Authentication0.html">
            
                    
                    Django入门与实践-第14章：用户注册
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="Authentication1.html">
            
                <a href="Authentication1.html">
            
                    
                    Django入门与实践-第15章：用户注销
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="Authentication2.html">
            
                <a href="Authentication2.html">
            
                    
                    Django入门与实践-第16章：用户登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="DjangoORM0.html">
            
                <a href="DjangoORM0.html">
            
                    
                    Django入门与实践-第17章：保护视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="DjangoORM1.html">
            
                <a href="DjangoORM1.html">
            
                    
                    Django入门与实践-第18章：实现主题回复列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="DjangoORM2.html">
            
                <a href="DjangoORM2.html">
            
                    
                    Django入门与实践-第19章：实现主题回复功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="DjangoORM3.html">
            
                <a href="DjangoORM3.html">
            
                    
                    Django入门与实践-第20章：查询结果集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="DjangoORM.html">
            
                <a href="DjangoORM.html">
            
                    
                    Django入门与实践-第21章：Django数据迁移
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="ClassBasedViews0.html">
            
                <a href="ClassBasedViews0.html">
            
                    
                    Django入门与实践-第22章：基于类的视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.24" data-path="ClassBasedViews1.html">
            
                <a href="ClassBasedViews1.html">
            
                    
                    Django入门与实践-第23章：分页实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="ClassBasedViews2.html">
            
                <a href="ClassBasedViews2.html">
            
                    
                    Django入门与实践-第24章：我的账户
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="ClassBasedViews3.html">
            
                <a href="ClassBasedViews3.html">
            
                    
                    Django入门与实践-第25章：Markdown支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" data-path="ClassBasedViews4.html">
            
                <a href="ClassBasedViews4.html">
            
                    
                    Django入门与实践-第26章：个性化设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="Deployment.html">
            
                <a href="Deployment.html">
            
                    
                    Django入门与实践-第27章：项目部署
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Django入门与实践-第14章：用户注册</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="django&#x5165;&#x95E8;&#x4E0E;&#x5B9E;&#x8DF5;-&#x7B2C;14&#x7AE0;&#xFF1A;&#x7528;&#x6237;&#x6CE8;&#x518C;">Django&#x5165;&#x95E8;&#x4E0E;&#x5B9E;&#x8DF5;-&#x7B2C;14&#x7AE0;&#xFF1A;&#x7528;&#x6237;&#x6CE8;&#x518C;</h1>
<p><img src="statics/4-1.jpg" alt=""></p>
<h3 id="&#x524D;&#x8A00;">&#x524D;&#x8A00;</h3>
<p>&#x8FD9;&#x4E00;&#x7AE0;&#x8282;&#x5C06;&#x4F1A;&#x5168;&#x9762;&#x4ECB;&#x7ECD; Django &#x7684;&#x8EAB;&#x4EFD;&#x8BA4;&#x8BC1;&#x7CFB;&#x7EDF;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x5B9E;&#x73B0;&#x6CE8;&#x518C;&#x3001;&#x767B;&#x5F55;&#x3001;&#x6CE8;&#x9500;&#x3001;&#x5BC6;&#x7801;&#x91CD;&#x7F6E;&#x548C;&#x5BC6;&#x7801;&#x4FEE;&#x6539;&#x7684;&#x6574;&#x5957;&#x6D41;&#x7A0B;&#x3002;</p>
<p>&#x540C;&#x65F6;&#x4F60;&#x8FD8;&#x4F1A;&#x4E86;&#x89E3;&#x5230;&#x5982;&#x4F55;&#x4FDD;&#x62A4;&#x67D0;&#x4E9B;&#x8BD5;&#x56FE;&#x4EE5;&#x9632;&#x672A;&#x6388;&#x6743;&#x7684;&#x7528;&#x6237;&#x8BBF;&#x95EE;&#xFF0C;&#x4EE5;&#x53CA;&#x5982;&#x4F55;&#x8BBF;&#x95EE;&#x5DF2;&#x767B;&#x5F55;&#x7528;&#x6237;&#x7684;&#x4E2A;&#x4EBA;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x5728;&#x63A5;&#x4E0B;&#x6765;&#x7684;&#x90E8;&#x5206;&#xFF0C;&#x4F60;&#x4F1A;&#x770B;&#x5230;&#x4E00;&#x4E9B;&#x548C;&#x8EAB;&#x4EFD;&#x9A8C;&#x8BC1;&#x6709;&#x5173;&#x7EBF;&#x6846;&#x56FE;&#xFF0C;&#x5C06;&#x5728;&#x672C;&#x6559;&#x7A0B;&#x4E2D;&#x5B9E;&#x73B0;&#x3002;&#x4E4B;&#x540E;&#x662F;&#x4E00;&#x4E2A;&#x5168;&#x65B0;Django &#x5E94;&#x7528;&#x7684;&#x521D;&#x59CB;&#x5316;&#x8BBE;&#x7F6E;&#x3002;&#x81F3;&#x4ECA;&#x4E3A;&#x6B62;&#x6211;&#x4EEC;&#x4E00;&#x76F4;&#x5728;&#x4E00;&#x4E2A;&#x540D;&#x53EB; boards &#x7684;&#x5E94;&#x7528;&#x4E2D;&#x5F00;&#x53D1;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x6240;&#x6709;&#x8EAB;&#x4EFD;&#x8BA4;&#x8BC1;&#x76F8;&#x5173;&#x7684;&#x5185;&#x5BB9;&#x90FD;&#x5C06;&#x5728;&#x53E6;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x4E2D;&#xFF0C;&#x8FD9;&#x6837;&#x80FD;&#x66F4;&#x826F;&#x597D;&#x7684;&#x7EC4;&#x7EC7;&#x4EE3;&#x7801;&#x3002;
<img src="statics/4-2.jpg" alt=""></p>
<h3 id="&#x7EBF;&#x6846;&#x56FE;">&#x7EBF;&#x6846;&#x56FE;</h3>
<p>&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x66F4;&#x65B0;&#x4E00;&#x4E0B;&#x5E94;&#x7528;&#x7684;&#x7EBF;&#x6846;&#x56FE;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x9876;&#x90E8;&#x83DC;&#x5355;&#x6DFB;&#x52A0;&#x4E00;&#x4E9B;&#x65B0;&#x9009;&#x9879;&#xFF0C;&#x5982;&#x679C;&#x7528;&#x6237;&#x672A;&#x901A;&#x8FC7;&#x8EAB;&#x4EFD;&#x9A8C;&#x8BC1;&#xFF0C;&#x5E94;&#x8BE5;&#x6709;&#x4E24;&#x4E2A;&#x6309;&#x94AE;&#xFF1A;&#x5206;&#x522B;&#x662F;&#x6CE8;&#x518C;&#x548C;&#x767B;&#x5F55;&#x6309;&#x94AE;&#x3002;</p>
<p><img src="statics/4-3.png" alt="Wireframe Top Menu"></p>
<p>&#x56FE;1: &#x672A;&#x8BA4;&#x8BC1;&#x7528;&#x6237;&#x7684;&#x83DC;&#x5355;&#x9876;&#x90E8;</p>
<p>&#x5982;&#x679C;&#x7528;&#x6237;&#x5DF2;&#x7ECF;&#x901A;&#x8FC7;&#x8EAB;&#x4EFD;&#x8BA4;&#x8BC1;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x663E;&#x793A;&#x4ED6;&#x4EEC;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x548C;&#x5E26;&#x6709;&#x201C;&#x6211;&#x7684;&#x8D26;&#x6237;&#x201D;&#xFF0C;&#x201C;&#x4FEE;&#x6539;&#x5BC6;&#x7801;&#x201D;&#xFF0C;&#x201C;&#x767B;&#x51FA;&#x201D;&#x8FD9;&#x4E09;&#x4E2A;&#x9009;&#x9879;&#x7684;&#x4E0B;&#x62C9;&#x6846;</p>
<p><img src="statics/4-4.png" alt="Wireframe Top Menu"></p>
<p>&#x56FE;2: &#x8BA4;&#x8BC1;&#x7528;&#x6237;&#x7684;&#x9876;&#x90E8;&#x83DC;&#x5355;</p>
<p>&#x5728;&#x767B;&#x5F55;&#x9875;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x5E26;&#x6709;<strong>username</strong>&#x548C;<strong>password</strong>&#x7684;&#x8868;&#x5355;&#xFF0C; &#x4E00;&#x4E2A;&#x767B;&#x5F55;&#x7684;&#x6309;&#x94AE;&#x548C;&#x53EF;&#x8DF3;&#x8F6C;&#x5230;&#x6CE8;&#x518C;&#x9875;&#x9762;&#x548C;&#x5BC6;&#x7801;&#x91CD;&#x7F6E;&#x9875;&#x9762;&#x7684;&#x94FE;&#x63A5;&#x3002;</p>
<p><img src="statics/4-5.png" alt="Wireframe log in page"></p>
<p>&#x56FE;3&#xFF1A;&#x767B;&#x5F55;&#x9875;&#x9762;</p>
<p>&#x5728;&#x6CE8;&#x518C;&#x9875;&#x9762;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x6709;&#x5305;&#x542B;&#x56DB;&#x4E2A;&#x5B57;&#x6BB5;&#x7684;&#x8868;&#x5355;&#xFF1A;<strong>username&#xFF0C;email address, password</strong>&#x548C;<strong>password confirmation</strong>&#x3002;&#x540C;&#x65F6;&#xFF0C;&#x4E5F;&#x5E94;&#x8BE5;&#x6709;&#x4E00;&#x4E2A;&#x80FD;&#x591F;&#x8BBF;&#x95EE;&#x767B;&#x5F55;&#x9875;&#x9762;&#x94FE;&#x63A5;&#x3002;</p>
<p><img src="statics/4-6.png" alt="Wireframe sign up page"></p>
<p>&#x56FE;4&#xFF1A;&#x6CE8;&#x518C;&#x9875;&#x9762;</p>
<p>&#x5728;&#x5BC6;&#x7801;&#x91CD;&#x7F6E;&#x9875;&#x9762;&#x4E0A;&#xFF0C;&#x53EA;&#x6709;<strong>email address</strong>&#x5B57;&#x6BB5;&#x7684;&#x8868;&#x5355;&#x3002;</p>
<p><img src="statics/4-7.png" alt="Wireframe password reset page"></p>
<p>&#x56FE;5: &#x5BC6;&#x7801;&#x91CD;&#x7F6E;</p>
<p>&#x4E4B;&#x540E;&#xFF0C;&#x7528;&#x6237;&#x5728;&#x70B9;&#x51FB;&#x5E26;&#x6709;&#x7279;&#x6B8A;token&#x7684;&#x91CD;&#x7F6E;&#x5BC6;&#x7801;&#x94FE;&#x63A5;&#x4EE5;&#x540E;&#xFF0C;&#x7528;&#x6237;&#x5C06;&#x88AB;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x4E00;&#x4E2A;&#x9875;&#x9762;&#xFF0C;&#x5728;&#x90A3;&#x91CC;&#x4ED6;&#x4EEC;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x65B0;&#x7684;&#x5BC6;&#x7801;&#x3002;</p>
<p><img src="statics/4-8.png" alt="Wireframe change password page"></p>
<p>&#x56FE;6&#xFF1A;&#x4FEE;&#x6539;&#x5BC6;&#x7801;</p>
<h3 id="&#x521D;&#x59CB;&#x8BBE;&#x7F6E;">&#x521D;&#x59CB;&#x8BBE;&#x7F6E;</h3>
<p>&#x8981;&#x7BA1;&#x7406;&#x8FD9;&#x4E9B;&#x529F;&#x80FD;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x53E6;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#xFF08;app&#xFF09;&#x4E2D;&#x5C06;&#x5176;&#x62C6;&#x89E3;&#x3002;&#x5728;&#x9879;&#x76EE;&#x6839;&#x76EE;&#x5F55;&#x4E2D;&#x7684; manage.py &#x6587;&#x4EF6;&#x6240;&#x5728;&#x7684;&#x540C;&#x4E00;&#x76EE;&#x5F55;&#x4E0B;&#xFF0C;&#x8FD0;&#x884C;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x4EE5;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;app&#xFF1A;</p>
<pre><code class="lang-shell">django-admin startapp accounts
</code></pre>
<p>&#x9879;&#x76EE;&#x7684;&#x76EE;&#x5F55;&#x7ED3;&#x6784;&#x5E94;&#x8BE5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-shell">myproject/
 |-- myproject/
 |    |-- accounts/     &lt;-- &#x65B0;&#x521B;&#x5EFA;&#x7684;app
 |    |-- boards/
 |    |-- myproject/
 |    |-- static/
 |    |-- templates/
 |    |-- db.sqlite3
 |    +-- manage.py
 +-- venv/
</code></pre>
<p>&#x4E0B;&#x4E00;&#x6B65;&#xFF0C;&#x5728; settings.py &#x6587;&#x4EF6;&#x4E2D;&#x5C06; <strong>accounts</strong> app &#x6DFB;&#x52A0;&#x5230;<code>INSTALLED_APPS</code>&#xFF1A;</p>
<pre><code class="lang-python">INSTALLED_APPS = [
    <span class="hljs-string">&apos;django.contrib.admin&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.auth&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.contenttypes&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.sessions&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.messages&apos;</span>,
    <span class="hljs-string">&apos;django.contrib.staticfiles&apos;</span>,

    <span class="hljs-string">&apos;widget_tweaks&apos;</span>,

    <span class="hljs-string">&apos;accounts&apos;</span>,
    <span class="hljs-string">&apos;boards&apos;</span>,
]
</code></pre>
<p>&#x73B0;&#x5728;&#x5F00;&#x59CB;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4F1A;&#x5728; <strong>accounts</strong> &#x8FD9;&#x4E2A;app&#x4E0B;&#x64CD;&#x4F5C;&#x3002;</p>
<p><img src="statics/4-9.jpg" alt=""></p>
<h3 id="&#x6CE8;&#x518C;">&#x6CE8;&#x518C;</h3>
<p>&#x6211;&#x4EEC;&#x4ECE;&#x521B;&#x5EFA;&#x6CE8;&#x518C;&#x89C6;&#x56FE;&#x5F00;&#x59CB;&#x3002;&#x9996;&#x5148;&#xFF0C;&#x5728;<code>urls.py</code> &#x6587;&#x4EF6;&#x4E2D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x8DEF;&#x7531;&#xFF1A;</p>
<p><strong>myproject/urls.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.conf.urls <span class="hljs-keyword">import</span> url
<span class="hljs-keyword">from</span> django.contrib <span class="hljs-keyword">import</span> admin

<span class="hljs-keyword">from</span> accounts <span class="hljs-keyword">import</span> views <span class="hljs-keyword">as</span> accounts_views
<span class="hljs-keyword">from</span> boards <span class="hljs-keyword">import</span> views

urlpatterns = [
    url(<span class="hljs-string">r&apos;^$&apos;</span>, views.home, name=<span class="hljs-string">&apos;home&apos;</span>),
    url(<span class="hljs-string">r&apos;^signup/$&apos;</span>, accounts_views.signup, name=<span class="hljs-string">&apos;signup&apos;</span>),
    url(<span class="hljs-string">r&apos;^boards/(?P&lt;pk&gt;\d+)/$&apos;</span>, views.board_topics, name=<span class="hljs-string">&apos;board_topics&apos;</span>),
    url(<span class="hljs-string">r&apos;^boards/(?P&lt;pk&gt;\d+)/new/$&apos;</span>, views.new_topic, name=<span class="hljs-string">&apos;new_topic&apos;</span>),
    url(<span class="hljs-string">r&apos;^admin/&apos;</span>, admin.site.urls),
]
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x6211;&#x4EEC;&#x4EE5;&#x4E0D;&#x540C;&#x7684;&#x65B9;&#x5F0F;&#x4ECE;<code>accounts</code> app &#x5BFC;&#x5165;&#x4E86;<code>views</code>&#x6A21;&#x5757;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> accounts <span class="hljs-keyword">import</span> views <span class="hljs-keyword">as</span> accounts_views
</code></pre>
<p>&#x6211;&#x4EEC;&#x7ED9; accounts &#x7684; <code>views</code> &#x6307;&#x5B9A;&#x4E86;&#x522B;&#x540D;&#xFF0C;&#x5426;&#x5219;&#x5B83;&#x4F1A;&#x4E0E;<code>boards</code> &#x7684;<code>views</code> &#x6A21;&#x5757;&#x53D1;&#x751F;&#x51B2;&#x7A81;&#x3002;&#x7A0D;&#x540E;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x6539;&#x8FDB;<code>urls.py</code> &#x7684;&#x8BBE;&#x8BA1;&#xFF0C;&#x4F46;&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x5173;&#x6CE8;&#x8EAB;&#x4EFD;&#x9A8C;&#x8BC1;&#x529F;&#x80FD;&#x3002;</p>
<p>&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x5728; accounts app &#x4E2D;&#x7F16;&#x8F91; <strong>views.py</strong>&#xFF0C;&#x65B0;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<strong>signup</strong>&#x7684;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#xFF1A;</p>
<p><strong>accounts/views.py</strong></p>
<pre><code class="lang-shell">from django.shortcuts import render

def signup(request):
    return render(request, &apos;signup.html&apos;)
</code></pre>
<p>&#x63A5;&#x7740;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x6A21;&#x677F;&#xFF0C;&#x53D6;&#x540D;&#x4E3A;<strong>signup.html</strong>&#xFF1A;</p>
<p><strong>templates/signup.html</strong></p>
<pre><code class="lang-html">{% extends &apos;base.html&apos; %}

{% block content %}
  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Sign up<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
{% endblock %}
</code></pre>
<p>&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x6253;&#x5F00; <a href="http://127.0.0.1:8000/signup/" target="_blank">http://127.0.0.1:8000/signup/</a> &#xFF0C;&#x770B;&#x770B;&#x662F;&#x5426;&#x7A0B;&#x5E8F;&#x8FD0;&#x884C;&#x4E86;&#x8D77;&#x6765;&#xFF1A;</p>
<p><img src="statics/4-10.png" alt="Sign up"></p>
<p>&#x63A5;&#x4E0B;&#x6765;&#x5199;&#x70B9;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#xFF1A;</p>
<p><strong>accounts/tests.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.core.urlresolvers <span class="hljs-keyword">import</span> reverse
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> resolve
<span class="hljs-keyword">from</span> django.test <span class="hljs-keyword">import</span> TestCase
<span class="hljs-keyword">from</span> .views <span class="hljs-keyword">import</span> signup

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_signup_status_code</span><span class="hljs-params">(self)</span>:</span>
        url = reverse(<span class="hljs-string">&apos;signup&apos;</span>)
        response = self.client.get(url)
        self.assertEquals(response.status_code, <span class="hljs-number">200</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_signup_url_resolves_signup_view</span><span class="hljs-params">(self)</span>:</span>
        view = resolve(<span class="hljs-string">&apos;/signup/&apos;</span>)
        self.assertEquals(view.func, signup)
</code></pre>
<p>&#x6D4B;&#x8BD5;&#x72B6;&#x6001;&#x7801;&#xFF08;200=success&#xFF09;&#x4EE5;&#x53CA; URL <strong>/signup/</strong> &#x662F;&#x5426;&#x8FD4;&#x56DE;&#x4E86;&#x6B63;&#x786E;&#x7684;&#x89C6;&#x56FE;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-shell">python manage.py test
</code></pre>
<pre><code class="lang-shell">Creating test database for alias &apos;default&apos;...
System check identified no issues (0 silenced).
..................
----------------------------------------------------------------------
Ran 18 tests in 0.652s

OK
Destroying test database for alias &apos;default&apos;...
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x8BA4;&#x8BC1;&#x89C6;&#x56FE;&#xFF08;&#x6CE8;&#x518C;&#x3001;&#x767B;&#x5F55;&#x3001;&#x5BC6;&#x7801;&#x91CD;&#x7F6E;&#x7B49;&#xFF09;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x9876;&#x90E8;&#x6761;&#x548C;breadcrumb&#x5BFC;&#x822A;&#x680F;&#xFF0C;&#x4F46;&#x4ECD;&#x7136;&#x80FD;&#x591F;&#x590D;&#x7528;<strong>base.html</strong> &#x6A21;&#x677F;&#xFF0C;&#x4E0D;&#x8FC7;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5BF9;&#x5B83;&#x505A;&#x51FA;&#x4E00;&#x4E9B;&#x4FEE;&#x6539;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x5FAE;&#x8C03;&#xFF1A;</p>
<p><strong>templates/base.html</strong></p>
<pre><code class="lang-html">{% load static %}<span class="hljs-meta">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;utf-8&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>{% block title %}Django Boards{% endblock %}<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;https://fonts.googleapis.com/css?family=Peralta&quot;</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/bootstrap.min.css&apos; %}&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/app.css&apos; %}&quot;</span>&gt;</span>
    {% block stylesheet %}{% endblock %}  <span class="hljs-comment">&lt;!-- &#x8FD9;&#x91CC; --&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    {% block body %}  <span class="hljs-comment">&lt;!-- &#x8FD9;&#x91CC; --&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar navbar-expand-lg navbar-dark bg-dark&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-brand&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;home&apos; %}&quot;</span>&gt;</span>Django Boards<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ol</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;breadcrumb my-4&quot;</span>&gt;</span>
          {% block breadcrumb %}
          {% endblock %}
        <span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
        {% block content %}
        {% endblock %}
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    {% endblock body %}  <span class="hljs-comment">&lt;!-- &#x8FD9;&#x91CC; --&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>&#x6211;&#x5728; <strong>base.html</strong> &#x6A21;&#x677F;&#x4E2D;&#x6807;&#x6CE8;&#x4E86;&#x6CE8;&#x91CA;&#xFF0C;&#x8868;&#x793A;&#x65B0;&#x52A0;&#x7684;&#x4EE3;&#x7801;&#x3002;&#x5757;&#x4EE3;&#x7801;<code>{% block stylesheet %}{% endblock %}</code> &#x8868;&#x793A;&#x6DFB;&#x52A0;&#x4E00;&#x4E9B;&#x989D;&#x5916;&#x7684;CSS&#xFF0C;&#x7528;&#x4E8E;&#x67D0;&#x4E9B;&#x7279;&#x5B9A;&#x7684;&#x9875;&#x9762;&#x3002;</p>
<p>&#x4EE3;&#x7801;&#x5757;<code>{% block body %}</code> &#x5305;&#x88C5;&#x4E86;&#x6574;&#x4E2A;HTML&#x6587;&#x6863;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x7A7A;&#x7684;&#x6587;&#x6863;&#x7ED3;&#x6784;&#xFF0C;&#x4EE5;&#x5145;&#x5206;&#x5229;&#x7528;<strong>base.html</strong>&#x5934;&#x90E8;&#x3002;&#x6CE8;&#x610F;&#xFF0C;&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x7ED3;&#x675F;&#x7684;&#x4EE3;&#x7801;&#x5757;<code>{% endblock body %}</code>&#xFF0C;&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x547D;&#x540D;&#x7ED3;&#x675F;&#x6807;&#x7B7E;&#x662F;&#x4E00;&#x79CD;&#x5F88;&#x597D;&#x7684;&#x5B9E;&#x8DF5;&#x65B9;&#x6CD5;&#xFF0C;&#x8FD9;&#x6837;&#x66F4;&#x5BB9;&#x6613;&#x786E;&#x5B9A;&#x7ED3;&#x675F;&#x6807;&#x8BB0;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5728;<strong>signup.html</strong>&#x6A21;&#x677F;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x4F7F;&#x7528;<code>{% block body %}</code>&#x4EE3;&#x66FF;&#x4E86; <code>{% block content %}</code></p>
<p><strong>templates/signup.html</strong></p>
<pre><code class="lang-shell">{% extends &apos;base.html&apos; %}

{% block body %}
  &lt;h2&gt;Sign up&lt;/h2&gt;
{% endblock %}
</code></pre>
<p><img src="statics/4-11.png" alt="Sign up"></p>
<p><img src="statics/4-12.jpg" alt="Too Empty"></p>
<p>&#x662F;&#x65F6;&#x5019;&#x521B;&#x5EFA;&#x6CE8;&#x518C;&#x8868;&#x5355;&#x4E86;&#x3002;Django&#x6709;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <strong>UserCreationForm</strong>&#x7684;&#x5185;&#x7F6E;&#x8868;&#x5355;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x4F7F;&#x7528;&#x5B83;&#x5427;&#xFF1A;</p>
<p><strong>accounts/views.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth.forms <span class="hljs-keyword">import</span> UserCreationForm
<span class="hljs-keyword">from</span> django.shortcuts <span class="hljs-keyword">import</span> render

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">signup</span><span class="hljs-params">(request)</span>:</span>
    form = UserCreationForm()
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">&apos;signup.html&apos;</span>, {<span class="hljs-string">&apos;form&apos;</span>: form})
</code></pre>
<p><strong>templates/signup.html</strong></p>
<pre><code class="lang-html">{% extends &apos;base.html&apos; %}

{% block body %}
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Sign up<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span> <span class="hljs-attr">novalidate</span>&gt;</span>
      {% csrf_token %}
      {{ form.as_p }}
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary&quot;</span>&gt;</span>Create an account<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
{% endblock %}
</code></pre>
<p><img src="statics/4-13.png" alt="Sign up"></p>
<p>&#x770B;&#x8D77;&#x6765;&#x6709;&#x4E00;&#x70B9;&#x4E71;&#x7CDF;&#x7CDF;,&#x662F;&#x5427;&#xFF1F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<strong>form.html</strong>&#x6A21;&#x677F;&#x4F7F;&#x5B83;&#x770B;&#x8D77;&#x6765;&#x66F4;&#x597D;&#xFF1A;</p>
<p><strong>templates/signup.html</strong></p>
<pre><code class="lang-html">{% extends &apos;base.html&apos; %}

{% block body %}
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Sign up<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span> <span class="hljs-attr">novalidate</span>&gt;</span>
      {% csrf_token %}
      {% include &apos;includes/form.html&apos; %}
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary&quot;</span>&gt;</span>Create an account<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
{% endblock %}
</code></pre>
<p><img src="statics/4-14.png" alt="Sign up"></p>
<p>&#x54C8;&#xFF1F;&#x975E;&#x5E38;&#x63A5;&#x8FD1;&#x76EE;&#x6807;&#x4E86;&#xFF0C;&#x76EE;&#x524D;&#xFF0C;&#x6211;&#x4EEC;&#x7684;<strong>form.html</strong>&#x90E8;&#x5206;&#x6A21;&#x677F;&#x663E;&#x793A;&#x4E86;&#x4E00;&#x4E9B;&#x539F;&#x751F;&#x7684;HTML&#x4EE3;&#x7801;&#x3002;&#x8FD9;&#x662F;django&#x51FA;&#x4E8E;&#x5B89;&#x5168;&#x8003;&#x8651;&#x7684;&#x7279;&#x6027;&#x3002;&#x5728;&#x9ED8;&#x8BA4;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;Django&#x5C06;&#x6240;&#x6709;&#x5B57;&#x7B26;&#x4E32;&#x89C6;&#x4E3A;&#x4E0D;&#x5B89;&#x5168;&#x7684;&#xFF0C;&#x4F1A;&#x8F6C;&#x4E49;&#x6240;&#x6709;&#x53EF;&#x80FD;&#x5BFC;&#x81F4;&#x95EE;&#x9898;&#x7684;&#x7279;&#x6B8A;&#x5B57;&#x7B26;&#x3002;&#x4F46;&#x5728;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4FE1;&#x4EFB;&#x5B83;&#x3002;</p>
<p><strong>templates/includes/form.html</strong></p>
<pre><code class="lang-html">{% load widget_tweaks %}

{% for field in form %}
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-group&quot;</span>&gt;</span>
    {{ field.label_tag }}

    <span class="hljs-comment">&lt;!-- code suppressed for brevity --&gt;</span>

    {% if field.help_text %}
      <span class="hljs-tag">&lt;<span class="hljs-name">small</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-text text-muted&quot;</span>&gt;</span>
        {{ field.help_text|safe }}  <span class="hljs-comment">&lt;!-- &#x65B0;&#x7684;&#x4EE3;&#x7801; --&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">small</span>&gt;</span>
    {% endif %}
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
{% endfor %}
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E3B;&#x8981;&#x5728;&#x4E4B;&#x524D;&#x7684;&#x6A21;&#x677F;&#x4E2D;&#xFF0C;&#x5C06;&#x9009;&#x9879;<code>safe</code> &#x6DFB;&#x52A0;&#x5230;<code>field.help_text</code>: <code>{{ field.help_text|safe }}</code>.</p>
<p>&#x4FDD;&#x5B58;<strong>form.html</strong>&#x6587;&#x4EF6;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x6B21;&#x68C0;&#x6D4B;&#x6CE8;&#x518C;&#x9875;&#x9762;&#xFF1A;</p>
<p><img src="statics/4-15.png" alt="Sign up"></p>
<p>&#x73B0;&#x5728;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x5728;<strong>signup</strong>&#x89C6;&#x56FE;&#x4E2D;&#x5B9E;&#x73B0;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF1A;</p>
<p><strong>accounts/views.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth <span class="hljs-keyword">import</span> login <span class="hljs-keyword">as</span> auth_login
<span class="hljs-keyword">from</span> django.contrib.auth.forms <span class="hljs-keyword">import</span> UserCreationForm
<span class="hljs-keyword">from</span> django.shortcuts <span class="hljs-keyword">import</span> render, redirect

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">signup</span><span class="hljs-params">(request)</span>:</span>
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">&apos;POST&apos;</span>:
        form = UserCreationForm(request.POST)
        <span class="hljs-keyword">if</span> form.is_valid():
            user = form.save()
            auth_login(request, user)
            <span class="hljs-keyword">return</span> redirect(<span class="hljs-string">&apos;home&apos;</span>)
    <span class="hljs-keyword">else</span>:
        form = UserCreationForm()
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">&apos;signup.html&apos;</span>, {<span class="hljs-string">&apos;form&apos;</span>: form})
</code></pre>
<p>&#x8868;&#x5355;&#x5904;&#x7406;&#x6709;&#x4E00;&#x4E2A;&#x5C0F;&#x7EC6;&#x8282;&#xFF1A;<strong>login</strong>&#x51FD;&#x6570;&#x91CD;&#x547D;&#x540D;&#x4E3A;<strong>auth_login</strong>&#x4EE5;&#x907F;&#x514D;&#x4E0E;&#x5185;&#x7F6E;login&#x89C6;&#x56FE;&#x51B2;&#x7A81;&#xFF09;&#x3002;</p>
<blockquote>
<p>&#xFF08;&#x7F16;&#x8005;&#x6CE8;&#xFF1A;&#x6211;&#x91CD;&#x547D;&#x540D;&#x4E86;<code>login</code> &#x51FD;&#x6570;&#x91CD;&#x547D;&#x540D;&#x4E3A;<code>auth_login</code> &#xFF0C;&#x4F46;&#x540E;&#x6765;&#x6211;&#x610F;&#x8BC6;&#x5230;Django1.11&#x5BF9;&#x767B;&#x5F55;&#x89C6;&#x56FE;LoginView&#x5177;&#x6709;&#x57FA;&#x4E8E;&#x7C7B;&#x7684;&#x89C6;&#x56FE;&#xFF0C;&#x56E0;&#x6B64;&#x4E0D;&#x5B58;&#x5728;&#x4E0E;&#x540D;&#x79F0;&#x51B2;&#x7A81;&#x7684;&#x98CE;&#x9669;&#x3002;&#x5728;&#x6BD4;&#x8F83;&#x65E7;&#x7684;&#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x6709;&#x4E00;&#x4E2A;<code>auth.login</code>&#x548C;<code>auth.view.login</code> &#xFF0C;&#x8FD9;&#x4F1A;&#x5BFC;&#x81F4;&#x4E00;&#x4E9B;&#x6DF7;&#x6DC6;&#xFF0C;&#x56E0;&#x4E3A;&#x4E00;&#x4E2A;&#x662F;&#x7528;&#x6237;&#x767B;&#x5F55;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x662F;&#x89C6;&#x56FE;&#x3002;</p>
<p>&#x7B80;&#x5355;&#x6765;&#x8BF4;&#xFF1A;&#x5982;&#x679C;&#x4F60;&#x613F;&#x610F;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x50CF;<code>login</code> &#x4E00;&#x6837;&#x5BFC;&#x5165;&#x5B83;&#xFF0C;&#x8FD9;&#x6837;&#x505A;&#x4E0D;&#x4F1A;&#x9020;&#x6210;&#x4EFB;&#x4F55;&#x95EE;&#x9898;&#x3002;&#xFF09;</p>
</blockquote>
<p>&#x5982;&#x679C;&#x8868;&#x5355;&#x662F;&#x6709;&#x6548;&#x7684;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x901A;&#x8FC7;<code>user=form.save()</code>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;User&#x5B9E;&#x4F8B;&#x3002;&#x7136;&#x540E;&#x5C06;&#x521B;&#x5EFA;&#x7684;&#x7528;&#x6237;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7ED9;<code>auth_login</code>&#x51FD;&#x6570;&#xFF0C;&#x624B;&#x52A8;&#x9A8C;&#x8BC1;&#x7528;&#x6237;&#x3002;&#x4E4B;&#x540E;&#xFF0C;&#x89C6;&#x56FE;&#x5C06;&#x7528;&#x6237;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x4E3B;&#x9875;&#xFF0C;&#x4FDD;&#x6301;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x6D41;&#x7A0B;&#x3002;</p>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x8BD5;&#x8BD5;&#x5427;&#xFF0C;&#x9996;&#x5148;&#xFF0C;&#x63D0;&#x4EA4;&#x4E00;&#x4E9B;&#x65E0;&#x6548;&#x6570;&#x636E;&#xFF0C;&#x65E0;&#x8BBA;&#x662F;&#x7A7A;&#x8868;&#x5355;&#xFF0C;&#x4E0D;&#x5339;&#x914D;&#x7684;&#x5B57;&#x6BB5;&#x8FD8;&#x662F;&#x5DF2;&#x6709;&#x7684;&#x7528;&#x6237;&#x540D;&#x3002;</p>
<p><img src="statics/4-16.png" alt="Sign up"></p>
<p>&#x73B0;&#x5728;&#x586B;&#x5199;&#x8868;&#x5355;&#x5E76;&#x63D0;&#x4EA4;&#xFF0C;&#x68C0;&#x67E5;&#x7528;&#x6237;&#x662F;&#x5426;&#x5DF2;&#x521B;&#x5EFA;&#x5E76;&#x91CD;&#x5B9A;&#x5411;&#x5230;&#x4E3B;&#x9875;&#x3002;</p>
<p><img src="statics/4-17.png" alt="Sign up"></p>
<h3 id="&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x5F15;&#x7528;&#x5DF2;&#x8BA4;&#x8BC1;&#x7684;&#x7528;&#x6237;">&#x5728;&#x6A21;&#x677F;&#x4E2D;&#x5F15;&#x7528;&#x5DF2;&#x8BA4;&#x8BC1;&#x7684;&#x7528;&#x6237;</h3>
<p>&#x6211;&#x4EEC;&#x8981;&#x600E;&#x4E48;&#x624D;&#x80FD;&#x77E5;&#x9053;&#x4E0A;&#x8FF0;&#x64CD;&#x4F5C;&#x662F;&#x5426;&#x6709;&#x6548;&#x5462;&#xFF1F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7F16;&#x8F91;<strong>base.html</strong>&#x6A21;&#x677F;&#x6765;&#x5728;&#x9876;&#x90E8;&#x680F;&#x4E0A;&#x6DFB;&#x52A0;&#x7528;&#x6237;&#x540D;&#x79F0;&#xFF1A;</p>
<p><strong>templates/base.html</strong></p>
<pre><code class="lang-html">{% block body %}
  <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar navbar-expand-sm navbar-dark bg-dark&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-brand&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;home&apos; %}&quot;</span>&gt;</span>Django Boards<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-toggler&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">&quot;collapse&quot;</span> <span class="hljs-attr">data-target</span>=<span class="hljs-string">&quot;#mainMenu&quot;</span> <span class="hljs-attr">aria-controls</span>=<span class="hljs-string">&quot;mainMenu&quot;</span> <span class="hljs-attr">aria-expanded</span>=<span class="hljs-string">&quot;false&quot;</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Toggle navigation&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-toggler-icon&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;collapse navbar-collapse&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;mainMenu&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;navbar-nav ml-auto&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav-item&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;nav-link&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span>&gt;</span>{{ user.username }}<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ol</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;breadcrumb my-4&quot;</span>&gt;</span>
      {% block breadcrumb %}
      {% endblock %}
    <span class="hljs-tag">&lt;/<span class="hljs-name">ol</span>&gt;</span>
    {% block content %}
    {% endblock %}
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
{% endblock body %}
</code></pre>
<p><img src="statics/4-18.png" alt="4-17"></p>
<h3 id="&#x6D4B;&#x8BD5;&#x6CE8;&#x518C;&#x89C6;&#x56FE;">&#x6D4B;&#x8BD5;&#x6CE8;&#x518C;&#x89C6;&#x56FE;</h3>
<p>&#x6211;&#x4EEC;&#x6765;&#x6539;&#x8FDB;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#xFF1A;</p>
<p><strong>accounts/tests.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth.forms <span class="hljs-keyword">import</span> UserCreationForm
<span class="hljs-keyword">from</span> django.core.urlresolvers <span class="hljs-keyword">import</span> reverse
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> resolve
<span class="hljs-keyword">from</span> django.test <span class="hljs-keyword">import</span> TestCase
<span class="hljs-keyword">from</span> .views <span class="hljs-keyword">import</span> signup

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setUp</span><span class="hljs-params">(self)</span>:</span>
        url = reverse(<span class="hljs-string">&apos;signup&apos;</span>)
        self.response = self.client.get(url)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_signup_status_code</span><span class="hljs-params">(self)</span>:</span>
        self.assertEquals(self.response.status_code, <span class="hljs-number">200</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_signup_url_resolves_signup_view</span><span class="hljs-params">(self)</span>:</span>
        view = resolve(<span class="hljs-string">&apos;/signup/&apos;</span>)
        self.assertEquals(view.func, signup)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_csrf</span><span class="hljs-params">(self)</span>:</span>
        self.assertContains(self.response, <span class="hljs-string">&apos;csrfmiddlewaretoken&apos;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_contains_form</span><span class="hljs-params">(self)</span>:</span>
        form = self.response.context.get(<span class="hljs-string">&apos;form&apos;</span>)
        self.assertIsInstance(form, UserCreationForm)
</code></pre>
<p>&#x6211;&#x4EEC;&#x7A0D;&#x5FAE;&#x6539;&#x53D8;&#x4E86;<strong>SighUpTests</strong>&#x7C7B;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;<strong>setUp</strong>&#x65B9;&#x6CD5;&#xFF0C;&#x5C06;response&#x5BF9;&#x8C61;&#x79FB;&#x5230;&#x90A3;&#x91CC;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6D4B;&#x8BD5;&#x54CD;&#x5E94;&#x4E2D;&#x662F;&#x5426;&#x6709;&#x8868;&#x5355;&#x548C;CSRF token&#x3002;</p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x8981;&#x6D4B;&#x8BD5;&#x4E00;&#x4E2A;&#x6210;&#x529F;&#x7684;&#x6CE8;&#x518C;&#x529F;&#x80FD;&#x3002;&#x8FD9;&#x6B21;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7C7B;&#xFF0C;&#x4EE5;&#x4FBF;&#x4E8E;&#x66F4;&#x597D;&#x5730;&#x7EC4;&#x7EC7;&#x6D4B;&#x8BD5;&#x3002;</p>
<p><strong>accounts/tests.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth.models <span class="hljs-keyword">import</span> User
<span class="hljs-keyword">from</span> django.contrib.auth.forms <span class="hljs-keyword">import</span> UserCreationForm
<span class="hljs-keyword">from</span> django.core.urlresolvers <span class="hljs-keyword">import</span> reverse
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> resolve
<span class="hljs-keyword">from</span> django.test <span class="hljs-keyword">import</span> TestCase
<span class="hljs-keyword">from</span> .views <span class="hljs-keyword">import</span> signup

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-comment"># code suppressed...</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SuccessfulSignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setUp</span><span class="hljs-params">(self)</span>:</span>
        url = reverse(<span class="hljs-string">&apos;signup&apos;</span>)
        data = {
            <span class="hljs-string">&apos;username&apos;</span>: <span class="hljs-string">&apos;john&apos;</span>,
            <span class="hljs-string">&apos;password1&apos;</span>: <span class="hljs-string">&apos;abcdef123456&apos;</span>,
            <span class="hljs-string">&apos;password2&apos;</span>: <span class="hljs-string">&apos;abcdef123456&apos;</span>
        }
        self.response = self.client.post(url, data)
        self.home_url = reverse(<span class="hljs-string">&apos;home&apos;</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_redirection</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&apos;&apos;&apos;
        A valid form submission should redirect the user to the home page
        &apos;&apos;&apos;</span>
        self.assertRedirects(self.response, self.home_url)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_user_creation</span><span class="hljs-params">(self)</span>:</span>
        self.assertTrue(User.objects.exists())

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_user_authentication</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&apos;&apos;&apos;
        Create a new request to an arbitrary page.
        The resulting response should now have a `user` to its context,
        after a successful sign up.
        &apos;&apos;&apos;</span>
        response = self.client.get(self.home_url)
        user = response.context.get(<span class="hljs-string">&apos;user&apos;</span>)
        self.assertTrue(user.is_authenticated)
</code></pre>
<p>&#x8FD0;&#x884C;&#x8FD9;&#x4E2A;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x3002;</p>
<p>&#x4F7F;&#x7528;&#x7C7B;&#x4F3C;&#x5730;&#x7B56;&#x7565;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x7C7B;&#xFF0C;&#x7528;&#x4E8E;&#x6570;&#x636E;&#x65E0;&#x6548;&#x7684;&#x6CE8;&#x518C;&#x7528;&#x4F8B;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth.models <span class="hljs-keyword">import</span> User
<span class="hljs-keyword">from</span> django.contrib.auth.forms <span class="hljs-keyword">import</span> UserCreationForm
<span class="hljs-keyword">from</span> django.core.urlresolvers <span class="hljs-keyword">import</span> reverse
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> resolve
<span class="hljs-keyword">from</span> django.test <span class="hljs-keyword">import</span> TestCase
<span class="hljs-keyword">from</span> .views <span class="hljs-keyword">import</span> signup

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-comment"># code suppressed...</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SuccessfulSignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-comment"># code suppressed...</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">InvalidSignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setUp</span><span class="hljs-params">(self)</span>:</span>
        url = reverse(<span class="hljs-string">&apos;signup&apos;</span>)
        self.response = self.client.post(url, {})  <span class="hljs-comment"># submit an empty dictionary</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_signup_status_code</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&apos;&apos;&apos;
        An invalid form submission should return to the same page
        &apos;&apos;&apos;</span>
        self.assertEquals(self.response.status_code, <span class="hljs-number">200</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_form_errors</span><span class="hljs-params">(self)</span>:</span>
        form = self.response.context.get(<span class="hljs-string">&apos;form&apos;</span>)
        self.assertTrue(form.errors)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_dont_create_user</span><span class="hljs-params">(self)</span>:</span>
        self.assertFalse(User.objects.exists())
</code></pre>
<h3 id="&#x5C06;email&#x5B57;&#x6BB5;&#x6DFB;&#x52A0;&#x5230;&#x8868;&#x5355;">&#x5C06;Email&#x5B57;&#x6BB5;&#x6DFB;&#x52A0;&#x5230;&#x8868;&#x5355;</h3>
<p>&#x4E00;&#x5207;&#x90FD;&#x6B63;&#x5E38;&#xFF0C;&#x4F46;&#x8FD8;&#x7F3A;&#x5931; <strong>email address</strong>&#x5B57;&#x6BB5;&#x3002;<strong>UserCreationForm</strong>&#x4E0D;&#x63D0;&#x4F9B; email &#x5B57;&#x6BB5;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5BF9;&#x5B83;&#x8FDB;&#x884C;&#x6269;&#x5C55;&#x3002;</p>
<p>&#x5728;<strong>accounts</strong> &#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<strong>forms.py</strong>&#x7684;&#x6587;&#x4EF6;&#xFF1A;</p>
<p><strong>accounts/forms.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django <span class="hljs-keyword">import</span> forms
<span class="hljs-keyword">from</span> django.contrib.auth.forms <span class="hljs-keyword">import</span> UserCreationForm
<span class="hljs-keyword">from</span> django.contrib.auth.models <span class="hljs-keyword">import</span> User

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpForm</span><span class="hljs-params">(UserCreationForm)</span>:</span>
    email = forms.CharField(max_length=<span class="hljs-number">254</span>, required=<span class="hljs-keyword">True</span>, widget=forms.EmailInput())
    <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Meta</span>:</span>
        model = User
        fields = (<span class="hljs-string">&apos;username&apos;</span>, <span class="hljs-string">&apos;email&apos;</span>, <span class="hljs-string">&apos;password1&apos;</span>, <span class="hljs-string">&apos;password2&apos;</span>)
</code></pre>
<p>&#x73B0;&#x5728;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x9700;&#x8981;&#x5728;<code>views.py</code> &#x4E2D;&#x4F7F;&#x7528;UserCreationForm&#xFF0C;&#x800C;&#x662F;&#x5BFC;&#x5165;&#x65B0;&#x7684;&#x8868;&#x5355;<strong>SignUpForm</strong>&#xFF0C;&#x7136;&#x540E;&#x4F7F;&#x7528;&#x5B83;&#xFF1A;</p>
<p><strong>accounts/views.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth <span class="hljs-keyword">import</span> login <span class="hljs-keyword">as</span> auth_login
<span class="hljs-keyword">from</span> django.shortcuts <span class="hljs-keyword">import</span> render, redirect

<span class="hljs-keyword">from</span> .forms <span class="hljs-keyword">import</span> SignUpForm

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">signup</span><span class="hljs-params">(request)</span>:</span>
    <span class="hljs-keyword">if</span> request.method == <span class="hljs-string">&apos;POST&apos;</span>:
        form = SignUpForm(request.POST)
        <span class="hljs-keyword">if</span> form.is_valid():
            user = form.save()
            auth_login(request, user)
            <span class="hljs-keyword">return</span> redirect(<span class="hljs-string">&apos;home&apos;</span>)
    <span class="hljs-keyword">else</span>:
        form = SignUpForm()
    <span class="hljs-keyword">return</span> render(request, <span class="hljs-string">&apos;signup.html&apos;</span>, {<span class="hljs-string">&apos;form&apos;</span>: form})
</code></pre>
<p>&#x53EA;&#x7528;&#x8FD9;&#x4E2A;&#x5C0F;&#x5C0F;&#x7684;&#x6539;&#x53D8;&#xFF0C;&#x53EF;&#x4EE5;&#x8FD0;&#x4F5C;&#x4E86;&#xFF1A;</p>
<p><img src="statics/4-19.png" alt="signup"></p>
<p>&#x8BF7;&#x8BB0;&#x4F4F;&#x66F4;&#x6539;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x4EE5;&#x4F7F;&#x7528;SignUpForm&#x800C;&#x4E0D;&#x662F;UserCreationForm&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> .forms <span class="hljs-keyword">import</span> SignUpForm

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-comment"># ...</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_contains_form</span><span class="hljs-params">(self)</span>:</span>
        form = self.response.context.get(<span class="hljs-string">&apos;form&apos;</span>)
        self.assertIsInstance(form, SignUpForm)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SuccessfulSignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">setUp</span><span class="hljs-params">(self)</span>:</span>
        url = reverse(<span class="hljs-string">&apos;signup&apos;</span>)
        data = {
            <span class="hljs-string">&apos;username&apos;</span>: <span class="hljs-string">&apos;john&apos;</span>,
            <span class="hljs-string">&apos;email&apos;</span>: <span class="hljs-string">&apos;john@doe.com&apos;</span>,
            <span class="hljs-string">&apos;password1&apos;</span>: <span class="hljs-string">&apos;abcdef123456&apos;</span>,
            <span class="hljs-string">&apos;password2&apos;</span>: <span class="hljs-string">&apos;abcdef123456&apos;</span>
        }
        self.response = self.client.post(url, data)
        self.home_url = reverse(<span class="hljs-string">&apos;home&apos;</span>)

    <span class="hljs-comment"># ...</span>
</code></pre>
<p>&#x4E4B;&#x524D;&#x7684;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x4ECD;&#x7136;&#x4F1A;&#x901A;&#x8FC7;&#xFF0C;&#x56E0;&#x4E3A;SignUpForm&#x6269;&#x5C55;&#x4E86;UserCreationForm&#xFF0C;&#x5B83;&#x662F;UserCreationForm&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x4F8B;&#x3002;</p>
<p>&#x6DFB;&#x52A0;&#x4E86;&#x65B0;&#x7684;&#x8868;&#x5355;&#x540E;&#xFF0C;&#x8BA9;&#x6211;&#x4EEC;&#x60F3;&#x60F3;&#x53D1;&#x751F;&#x4E86;&#x4EC0;&#x4E48;&#xFF1A;</p>
<pre><code>fields = (&apos;username&apos;, &apos;email&apos;, &apos;password1&apos;, &apos;password2&apos;)
</code></pre><p>&#x5B83;&#x4F1A;&#x81EA;&#x52A8;&#x6620;&#x5C04;&#x5230;HTML&#x6A21;&#x677F;&#x4E2D;&#x3002;&#x8FD9;&#x5F88;&#x597D;&#x5417;&#xFF1F;&#x8FD9;&#x8981;&#x89C6;&#x60C5;&#x51B5;&#x800C;&#x5B9A;&#x3002;&#x5982;&#x679C;&#x5C06;&#x6765;&#x4F1A;&#x6709;&#x65B0;&#x7684;&#x5F00;&#x53D1;&#x4EBA;&#x5458;&#x60F3;&#x8981;&#x91CD;&#x65B0;&#x4F7F;&#x7528;SignUpForm&#x6765;&#x505A;&#x5176;&#x4ED6;&#x4E8B;&#x60C5;&#xFF0C;&#x5E76;&#x4E3A;&#x5176;&#x6DFB;&#x52A0;&#x4E00;&#x4E9B;&#x989D;&#x5916;&#x7684;&#x5B57;&#x6BB5;&#x3002;&#x90A3;&#x4E48;&#x8FD9;&#x4E9B;&#x65B0;&#x7684;&#x5B57;&#x6BB5;&#x4E5F;&#x4F1A;&#x51FA;&#x73B0;&#x5728;signup.html&#x4E2D;&#xFF0C;&#x8FD9;&#x53EF;&#x80FD;&#x4E0D;&#x662F;&#x6240;&#x671F;&#x671B;&#x7684;&#x884C;&#x4E3A;&#x3002;&#x8FD9;&#x79CD;&#x6539;&#x53D8;&#x53EF;&#x80FD;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x5E0C;&#x671B;&#x6709;&#x4EFB;&#x4F55;&#x610F;&#x5916;&#x3002;</p>
<p>&#x90A3;&#x4E48;&#x8BA9;&#x6211;&#x4EEC;&#x6765;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x6D4B;&#x8BD5;&#xFF0C;&#x9A8C;&#x8BC1;&#x6A21;&#x677F;&#x4E2D;&#x7684;HTML&#x8F93;&#x5165;&#xFF1A;</p>
<p><strong>accounts/tests.py</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpTests</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-comment"># ...</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_form_inputs</span><span class="hljs-params">(self)</span>:</span>
        <span class="hljs-string">&apos;&apos;&apos;
        The view must contain five inputs: csrf, username, email,
        password1, password2
        &apos;&apos;&apos;</span>
        self.assertContains(self.response, <span class="hljs-string">&apos;&lt;input&apos;</span>, <span class="hljs-number">5</span>)
        self.assertContains(self.response, <span class="hljs-string">&apos;type=&quot;text&quot;&apos;</span>, <span class="hljs-number">1</span>)
        self.assertContains(self.response, <span class="hljs-string">&apos;type=&quot;email&quot;&apos;</span>, <span class="hljs-number">1</span>)
        self.assertContains(self.response, <span class="hljs-string">&apos;type=&quot;password&quot;&apos;</span>, <span class="hljs-number">2</span>)
</code></pre>
<h3 id="&#x6539;&#x8FDB;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x7684;&#x7EC4;&#x7EC7;&#x7ED3;&#x6784;">&#x6539;&#x8FDB;&#x6D4B;&#x8BD5;&#x4EE3;&#x7801;&#x7684;&#x7EC4;&#x7EC7;&#x7ED3;&#x6784;</h3>
<p>&#x597D;&#x7684;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x6B63;&#x5728;&#x6D4B;&#x8BD5;&#x8F93;&#x5165;&#x548C;&#x6240;&#x6709;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x4F46;&#x662F;&#x6211;&#x4EEC;&#x4ECD;&#x7136;&#x5FC5;&#x987B;&#x6D4B;&#x8BD5;&#x8868;&#x5355;&#x672C;&#x8EAB;&#x3002;&#x4E0D;&#x8981;&#x53EA;&#x662F;&#x7EE7;&#x7EED;&#x5411;<code>accounts/tests.py</code> &#x6587;&#x4EF6;&#x6DFB;&#x52A0;&#x6D4B;&#x8BD5;&#xFF0C;&#x6211;&#x4EEC;&#x7A0D;&#x5FAE;&#x6539;&#x8FDB;&#x4E00;&#x4E0B;&#x9879;&#x76EE;&#x8BBE;&#x8BA1;&#x3002;</p>
<p>&#x5728;<strong>accounts</strong>&#x6587;&#x4EF6;&#x5939;&#x4E0B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<strong>tests</strong>&#x7684;&#x65B0;&#x6587;&#x4EF6;&#x5939;&#x3002;&#x7136;&#x540E;&#x5728;tests&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<code>init.py</code> &#x7684;&#x7A7A;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x73B0;&#x5728;&#xFF0C;&#x5C06;<code>test.py</code> &#x6587;&#x4EF6;&#x79FB;&#x52A8;&#x5230;<strong>tests</strong>&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#xFF0C;&#x5E76;&#x5C06;&#x5176;&#x91CD;&#x547D;&#x540D;&#x4E3A;<code>test_view_signup.py</code> </p>
<p>&#x6700;&#x7EC8;&#x7684;&#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-shell">myproject/
 |-- myproject/
 |    |-- accounts/
 |    |    |-- migrations/
 |    |    |-- tests/
 |    |    |    |-- __init__.py
 |    |    |    +-- test_view_signup.py
 |    |    |-- __init__.py
 |    |    |-- admin.py
 |    |    |-- apps.py
 |    |    |-- models.py
 |    |    +-- views.py
 |    |-- boards/
 |    |-- myproject/
 |    |-- static/
 |    |-- templates/
 |    |-- db.sqlite3
 |    +-- manage.py
 +-- venv/
</code></pre>
<p>&#x6CE8;&#x610F;&#x5230;&#xFF0C;&#x56E0;&#x4E3A;&#x6211;&#x4EEC;&#x5728;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x4F7F;&#x7528;&#x4E86;&#x76F8;&#x5BF9;&#x5BFC;&#x5165;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728; <strong>test_view_signup.py</strong>&#x4E2D;&#x4FEE;&#x590D;&#x5BFC;&#x5165;&#xFF1A;</p>
<p><strong>accounts/tests/test_view_signup.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib.auth.models <span class="hljs-keyword">import</span> User
<span class="hljs-keyword">from</span> django.core.urlresolvers <span class="hljs-keyword">import</span> reverse
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> resolve
<span class="hljs-keyword">from</span> django.test <span class="hljs-keyword">import</span> TestCase

<span class="hljs-keyword">from</span> ..views <span class="hljs-keyword">import</span> signup
<span class="hljs-keyword">from</span> ..forms <span class="hljs-keyword">import</span> SignUpForm
</code></pre>
<p>&#x6211;&#x4EEC;&#x5728;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x6A21;&#x5757;&#x5185;&#x90E8;&#x4F7F;&#x7528;&#x76F8;&#x5BF9;&#x5BFC;&#x5165;&#xFF0C;&#x4EE5;&#x4FBF;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x81EA;&#x7531;&#x5730;&#x91CD;&#x65B0;&#x547D;&#x540D;Django&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#xFF0C;&#x800C;&#x65E0;&#x9700;&#x4FEE;&#x590D;&#x6240;&#x6709;&#x7EDD;&#x5BF9;&#x5BFC;&#x5165;&#x3002;</p>
<p>&#x73B0;&#x5728;&#x8BA9;&#x6211;&#x4EEC;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x6D4B;&#x8BD5;&#x6587;&#x4EF6;&#x6765;&#x6D4B;&#x8BD5;SignUpForm&#xFF0C;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;<strong>test_form_signup.py</strong>&#x7684;&#x65B0;&#x6D4B;&#x8BD5;&#x6587;&#x4EF6;&#xFF1A;</p>
<p><strong>accounts/tests/test_form_signup.py</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.test <span class="hljs-keyword">import</span> TestCase
<span class="hljs-keyword">from</span> ..forms <span class="hljs-keyword">import</span> SignUpForm

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SignUpFormTest</span><span class="hljs-params">(TestCase)</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test_form_has_fields</span><span class="hljs-params">(self)</span>:</span>
        form = SignUpForm()
        expected = [<span class="hljs-string">&apos;username&apos;</span>, <span class="hljs-string">&apos;email&apos;</span>, <span class="hljs-string">&apos;password1&apos;</span>, <span class="hljs-string">&apos;password2&apos;</span>,]
        actual = list(form.fields)
        self.assertSequenceEqual(expected, actual)
</code></pre>
<p>&#x5B83;&#x770B;&#x8D77;&#x6765;&#x975E;&#x5E38;&#x4E25;&#x683C;&#x5BF9;&#x5427;&#xFF0C;&#x4F8B;&#x5982;&#xFF0C;&#x5982;&#x679C;&#x5C06;&#x6765;&#x6211;&#x4EEC;&#x5FC5;&#x987B;&#x66F4;&#x6539;SignUpForm&#xFF0C;&#x4EE5;&#x5305;&#x542B;&#x7528;&#x6237;&#x7684;&#x540D;&#x5B57;&#x548C;&#x59D3;&#x6C0F;&#xFF0C;&#x90A3;&#x4E48;&#x5373;&#x4F7F;&#x6211;&#x4EEC;&#x6CA1;&#x6709;&#x7834;&#x574F;&#x4EFB;&#x4F55;&#x4E1C;&#x897F;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x80FD;&#x6700;&#x7EC8;&#x4E0D;&#x5F97;&#x4E0D;&#x4FEE;&#x590D;&#x4E00;&#x4E9B;&#x6D4B;&#x8BD5;&#x7528;&#x4F8B;&#x3002;</p>
<p>!<img src="statics/4-20.jpg" alt=""></p>
<p>&#x8FD9;&#x4E9B;&#x8B66;&#x62A5;&#x5F88;&#x6709;&#x7528;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x4EEC;&#x6709;&#x52A9;&#x4E8E;&#x63D0;&#x9AD8;&#x8BA4;&#x8BC6;&#xFF0C;&#x7279;&#x522B;&#x662F;&#x65B0;&#x624B;&#x7B2C;&#x4E00;&#x6B21;&#x63A5;&#x89E6;&#x4EE3;&#x7801;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5E2E;&#x52A9;&#x4ED6;&#x4EEC;&#x81EA;&#x4FE1;&#x5730;&#x7F16;&#x7801;&#x3002;</p>
<h4 id="&#x6539;&#x8FDB;&#x6CE8;&#x518C;&#x6A21;&#x677F;">&#x6539;&#x8FDB;&#x6CE8;&#x518C;&#x6A21;&#x677F;</h4>
<p>&#x8BA9;&#x6211;&#x4EEC;&#x7A0D;&#x5FAE;&#x8BA8;&#x8BBA;&#x4E00;&#x4E0B;&#xFF0C;&#x5728;&#x8FD9;&#x91CC;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Bootstrap4 &#x7EC4;&#x4EF6;&#x6765;&#x4F7F;&#x5B83;&#x770B;&#x8D77;&#x6765;&#x4E0D;&#x9519;&#x3002;</p>
<p>&#x8BBF;&#x95EE;&#xFF1A;<a href="https://www.toptal.com/designers/subtlepatterns/" target="_blank">https://www.toptal.com/designers/subtlepatterns/</a> &#x5E76;&#x627E;&#x5230;&#x4E00;&#x4E2A;&#x5F88;&#x597D;&#x5730;&#x80CC;&#x666F;&#x56FE;&#x6848;&#x4F5C;&#x4E3A;&#x8D26;&#x6237;&#x9875;&#x9762;&#x7684;&#x80CC;&#x666F;&#xFF0C;&#x4E0B;&#x8F7D;&#x4E0B;&#x6765;&#x518D;&#x9759;&#x6001;&#x6587;&#x4EF6;&#x5939;&#x4E2D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;img&#x7684;&#x65B0;&#x6587;&#x4EF6;&#x5939;&#xFF0C;&#x5E76;&#x5C06;&#x56FE;&#x50CF;&#x653E;&#x7F6E;&#x518D;&#x90A3;&#x91CC;&#x3002;</p>
<p>&#x4E4B;&#x540E;&#xFF0C;&#x518D;static/css&#x4E2D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x540D;&#x4E3A;accounts.css&#x7684;&#x65B0;CSS&#x6587;&#x4EF6;&#x3002;&#x7ED3;&#x679C;&#x5E94;&#x8BE5;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-shell">myproject/
 |-- myproject/
 |    |-- accounts/
 |    |-- boards/
 |    |-- myproject/
 |    |-- static/
 |    |    |-- css/
 |    |    |    |-- accounts.css  &lt;-- here
 |    |    |    |-- app.css
 |    |    |    +-- bootstrap.min.css
 |    |    +-- img/
 |    |    |    +-- shattered.png  &lt;-- here (the name may be different, depending on the patter you downloaded)
 |    |-- templates/
 |    |-- db.sqlite3
 |    +-- manage.py
 +-- venv/
</code></pre>
<p>&#x73B0;&#x5728;&#x7F16;&#x8F91;accounts.css&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;</p>
<p><strong>static/css/accounts.css</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">background-image</span>: <span class="hljs-built_in">url</span>(../img/shattered.png);
}

<span class="hljs-selector-class">.logo</span> {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">&apos;Peralta&apos;</span>, cursive;
}

<span class="hljs-selector-class">.logo</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">rgba</span>(0,0,0,.9);
}

<span class="hljs-selector-class">.logo</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span>,
<span class="hljs-selector-class">.logo</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:active</span> {
  <span class="hljs-attribute">text-decoration</span>: none;
}
</code></pre>
<p>&#x5728;signup.html&#x6A21;&#x677F;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x5176;&#x6539;&#x4E3A;&#x4F7F;&#x7528;&#x65B0;&#x7684;CSS&#xFF0C;&#x5E76;&#x4F7F;&#x7528;Bootstrap4&#x7EC4;&#x4EF6;&#xFF1A;</p>
<p><strong>templates/signup.html</strong></p>
<pre><code class="lang-html">{% extends &apos;base.html&apos; %}

{% load static %}

{% block stylesheet %}
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">&quot;stylesheet&quot;</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% static &apos;css/accounts.css&apos; %}&quot;</span>&gt;</span>
{% endblock %}

{% block body %}
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-center logo my-4&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;{% url &apos;home&apos; %}&quot;</span>&gt;</span>Django Boards<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row justify-content-center&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-lg-8 col-md-10 col-sm-12&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card-body&quot;</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card-title&quot;</span>&gt;</span>Sign up<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">method</span>=<span class="hljs-string">&quot;post&quot;</span> <span class="hljs-attr">novalidate</span>&gt;</span>
              {% csrf_token %}
              {% include &apos;includes/form.html&apos; %}
              <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;submit&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-primary btn-block&quot;</span>&gt;</span>Create an account<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;card-footer text-muted text-center&quot;</span>&gt;</span>
            Already have an account? <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;#&quot;</span>&gt;</span>Log in<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
{% endblock %}
</code></pre>
<p>&#x8FD9;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x73B0;&#x5728;&#x7684;&#x6CE8;&#x518C;&#x9875;&#x9762;&#xFF1A;</p>
<p><img src="statics/signup-10.jpg" alt="Sign up"></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="AdvancedConcept3.html" class="navigation navigation-prev " aria-label="Previous page: Django入门与实践-第13章：表单处理">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Authentication1.html" class="navigation navigation-next " aria-label="Next page: Django入门与实践-第15章：用户注销">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Django入门与实践-第14章：用户注册","level":"1.15","depth":1,"next":{"title":"Django入门与实践-第15章：用户注销","level":"1.16","depth":1,"path":"Authentication1.md","ref":"./Authentication1.md","articles":[]},"previous":{"title":"Django入门与实践-第13章：表单处理","level":"1.14","depth":1,"path":"AdvancedConcept3.md","ref":"./AdvancedConcept3.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["include-codeblock","livereload"],"pluginsConfig":{"include-codeblock":{"check":false,"edit":false,"fixlang":false,"lang":"","template":"default","theme":"chrome","unindent":false},"livereload":{},"highlight":{},"search":{},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"sharing":{"all":["facebook","google","instapaper","twitter","weibo"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"fontsettings":{"family":"sans","size":2,"theme":"white"},"theme-default":{"showLevel":false,"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"ebook":"styles/ebook.css","epub":"styles/epub.css","mobi":"styles/mobi.css","pdf":"styles/pdf.css","print":"styles/print.css","website":"styles/website.css"}},"file":{"path":"Authentication0.md","mtime":"2018-05-13T13:48:46.854Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-05-13T12:52:49.928Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

